package com.zb.controller;

import com.alibaba.fastjson.JSONObject;
import com.zb.entity.Projectinfo;
import com.zb.service.ProjectinfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class ProjectController {
    @Autowired
    private ProjectinfoService projectinfoService;

    @RequestMapping(value = "ListProjectinfo",produces = {"application/json;charset=utf-8"})
    @ResponseBody
    public String ListProjectinfo(){
        List<Projectinfo> list = projectinfoService.listProjectinfo();
        return JSONObject.toJSONString(list);
    }


    @RequestMapping(value = "searchProjectinfo",produces = {"application/json;charset=utf-8"})
    @ResponseBody
    public String searchProjectinfo(int status){
        List<Projectinfo> list = projectinfoService.listProjectinfoByStatus(status);
        return JSONObject.toJSONString(list);
    }

        @RequestMapping("findById")
        public String findById(int id, Model model){
            Projectinfo project = projectinfoService.getProjectinfoById(id);
            model.addAttribute("p",project);
            return "shenhe.jsp";
        }

        @RequestMapping("shenhe")
        public String shenhe(int status,int id,Model model){
           int flag= projectinfoService.updateProjectinfo(status, id);
           model.addAttribute("flag",flag);
           return "list.jsp";
        }
}
